package robocup.component.actions;

/**
 * A say action, which is used by the player-agents to communicate. With these,
 * simple messages can be exchanged.
 */
public class SayAction
    extends Action {

  /**
   * The message. Note, that only few characters are allowed (see therefore at
   * NumberConverter.digits). The length of a message is limited to 10 chars per
   * default.
   */
  private String  _message;

  /**
   * Some messages require to be enclosed in qoutes, others not. The default is
   * <code>true</true>, which counts for all agents, except for the 
   * trainer.
   */
  private boolean quotesOn = true;

  /**
   * Constructor - a say-action
   * 
   * @param message
   *          the communicated message
   */
  public SayAction(
      final String message) {

    this._message = message;
    this._type = TYPE.SAY;
  }

  /**
   * Constructor - a say-action
   * 
   * @param message
   *          the communicated message
   * @param true,
   *          if the message should be enclosed in quotes
   */
  public SayAction(
      final String message,
      final boolean quotesOn) {

    this(message);
    this.quotesOn = quotesOn;
  }

  /**
   * Returns the actions string representation:
   * 
   * @return (say ["]&lt;message&gt;["])<br>
   *         <br>
   */
  @Override
  public String toString() {

    final StringBuffer buf = new StringBuffer();
    buf.append("(say ");
    if (this.quotesOn) {
      buf.append("\"");
    }
    buf.append(this._message);
    if (this.quotesOn) {
      buf.append("\"");
    }
    buf.append(")");

    return buf.toString();
  }

  /**
   * @return Returns the message.
   */
  public String getMessage() {

    return this._message;
  }

  /**
   * Sets a new message
   * 
   * @param message -
   *          the new message.
   */
  public void setMessage(final String message) {

    this._message = message;
  }
}
